"""
-------------------------------
- File_Name: printDesign.py.py
- Date: 2025/5/15
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description:
-------------------------------
"""

from fastapi import APIRouter, Depends, HTTPException
import json

from app.core.init_app import init_data
from app.core.security import get_current_user
from app.utils.responseUtil import ResponseUtil
from app.schemas.system.printDesign import PrintDesignIn
from app.dependencies.transactionDepend import get_db_pool
from app.database.oracleDBPool import OracleDBPool
from app.database.config import ORACLE_DB_CONFIG
from app.core.ctx import CTX_USER

router = APIRouter(prefix="/systemManage", dependencies=[Depends(get_current_user)])
tags = ["系统打印"]
description = "系统打印相关接口"


@router.post("/printDesign", summary="创建打印方案")
async def _(
        pd_in: PrintDesignIn,
        lmis17_pool: OracleDBPool = Depends(get_db_pool('lmis_17'))
):
    insert_sql = """
                    insert into print_design
                  (id, design_name, design_content, design_desc, create_time, create_by)
                values
                  (:id, :design_name, :design_content, :design_desc, :create_time, :create_by)
                """
    # pydantic 转dict
    insert_data_dict = pd_in.model_dump()
    # 将design_content 转json字符串, 禁止中文转Unicode 编码
    insert_data_dict['design_content'] = json.dumps(pd_in.design_content, ensure_ascii=False)
    # 自动获取连接、提交、释放
    lmis17_pool.execute_dml(insert_sql, insert_data_dict)
    return ResponseUtil.success_response(data=pd_in, msg=f"创建打印方案成功")
